package security;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.codec.binary.Base64;

public class Hash 
{
        public static final Base64 encoder = new Base64();
	
        private static String hashString(String message,String algorithme)
        {
            try 
            {
                MessageDigest digest=MessageDigest.getInstance(algorithme);
                byte[] msgBytes = digest.digest(message.getBytes());
                return encoder.encodeToString(msgBytes);
            } 
            catch (NoSuchAlgorithmException ex) 
            {
                return null;
            }            
	}       

        public static String generateSHA256(String message)
        {
            return hashString(message, "SHA-256");
        }
}
